//
//  UserAccoutViewModel.swift
//  SwiftWB
//
//  Created by 远成物流 on 2017/6/27.
//
//

import UIKit

class UserAccoutViewModel{

    static let shareInstance : UserAccoutViewModel = UserAccoutViewModel()
    
    var account:UserAccount?
    
    var accountPath : String{
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        return (path as String)+"account.plist"
    }
    
    var isLogin : Bool {
        if account == nil {
            return false
        }
        
        guard let expireDate = account?.expires_date else {
            return false
        }
        
        return expireDate.compare(Date()) == ComparisonResult.orderedDescending
    }
    
    init() {
        account = NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? UserAccount
    }
}
